package com.ict.web.controller.yzq;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ict.common.utils.poi.ExcelUtil;
import com.ict.web.domain.GovernmentDataResources;
import com.ict.web.service.IGovernmentDataResourcesService;
import com.ict.web.vo.UploadVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import com.ict.common.annotation.Log;
import com.ict.common.core.controller.BaseController;
import com.ict.common.core.domain.AjaxResult;
import com.ict.common.enums.BusinessType;
import com.ict.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 政务数据资源目录清单--刘杰Controller
 * 
 * @author ruoyi
 * @date 2022-03-13
 */
@Api(tags = "政务数据资源目录清单")
@RestController
@RequestMapping("/system/resources")
public class GovernmentDataResourcesController extends BaseController
{
    @Autowired
    private IGovernmentDataResourcesService governmentDataResourcesService;

    /**
     * 查询政务数据资源目录清单
     */
   @ApiOperation(value = "列表")
    @GetMapping("/list")
    public TableDataInfo list(GovernmentDataResources governmentDataResources)
    {
        startPage();
        List<GovernmentDataResources> list = governmentDataResourcesService.selectGovernmentDataResourcesList(governmentDataResources);
        return getDataTable(list);
    }

    /**
     * 导出政务数据资源目录清单
     */
   @ApiOperation(value = "导出")
    @Log(title = "政务数据资源目录清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GovernmentDataResources governmentDataResources)
    {
        List<GovernmentDataResources> list = governmentDataResourcesService.selectGovernmentDataResourcesList(governmentDataResources);
        ExcelUtil<GovernmentDataResources> util = new ExcelUtil<GovernmentDataResources>(GovernmentDataResources.class);
        util.exportExcel(response, list, "政务数据资源目录清单");
    }

    /**
     * 获取政务数据资源目录清单
     */
    @ApiOperation(value = "详情")
    @GetMapping(value = "/{governmentDataId}")
    public AjaxResult getInfo(@PathVariable("governmentDataId") Long governmentDataId)
    {
        return AjaxResult.success(governmentDataResourcesService.selectGovernmentDataResourcesByGovernmentDataId(governmentDataId));
    }
    /**
     * 批量导入目录文件.xls/.xlsx
     */
    @PostMapping("/batchFile")
    @ApiOperation(value ="批量导入目录文件")
    public AjaxResult batchInsertFile(@RequestParam(value = "file") MultipartFile file) throws IOException {
        UploadVo uploadVo = governmentDataResourcesService.batchInsertFile(file);
        if(CollectionUtils.isEmpty(uploadVo.getErrorVoList())){
            return AjaxResult.success(uploadVo);
        }
        return AjaxResult.error("操作失败",uploadVo.getErrorVoList());
    }
}
